package com.twsjw.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.twsjw.dao.userDAOImpl;
import com.twsjw.entity.Userinfo;


public class userAction {
	String uname;
	String upass;
	String result;
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public String getUname() {
		return uname;
	}
	public void setUname(String uname) {
		this.uname = uname;
	}
	public String getUpass() {
		return upass;
	}
	public void setUpass(String upass) {
		this.upass = upass;
	}
	public String execute()
	{
		userDAOImpl ud=new userDAOImpl();
		Userinfo u=ud.selectByNamePwd(uname, upass);
		ActionContext act=ActionContext.getContext();
		Map session=act.getSession();
		if(u!=null)
		{
			session.put("userid", u.getUserId());
			session.put("uname", u.getUsername());
			session.put("upass", u.getUserpass());
			return "success";
		}
		else
		{
			act.put("errorinfo", "t");
			return "fail";
		}
	}
	public String insert()
	{	
		userDAOImpl ud=new userDAOImpl();
		ud.insert(uname, upass);
		return "ok";
	}
	public String check()
	{
		userDAOImpl ud=new userDAOImpl();
		String id=ud.getInfo(uname);
		System.out.println("id in action"+id);
		if(id!=null&&id!="")
		{
			this.setResult("用户名已经存在！");
		}
		else
		{
			this.setResult("用户名可用！");
		}
		System.out.print(this.getResult());
		return "success";
		
	}
}
